import { useGlobalStore } from '~/store';
type ReplaceText = Record<string | number, string | number> | (number | string)[];
let store: any;
export const t = (key: string, replaceText?: ReplaceText) => {
    if (process.server) return '';
    if (!store) {
        store = useGlobalStore();
    }

    if (replaceText) {
        let replacedMessage = store.messages?.[key] || '';
        for (const k in replaceText) {
            const reg = new RegExp('{[^}]*' + k + '[^}]*}', 'g');
            replacedMessage = replacedMessage.replace(reg, replaceText[k] as string);
        }
        return replacedMessage;
    } else {
        return store.messages?.[key] || '';
    }
};
